//
//  HomeService.m
//  HxgProject
//
//  Created by hxg on 2018/3/26.
//  Copyright © 2018年 XMYY-19. All rights reserved.
//

#import "HomeService.h"
#import "NetworkManager.h"
#import "ResObject.h"
#import "PackageInfo.h"

@implementation HomeService

- (void)savePackageWithPackages:(PackageInfo *)packInfo
                withCallBack:(void(^)(ResObject *resObj)) callBack
{
    NetworkManager *man = [NetworkManager sharedNetworkManager];
    NSString *urlInfo = [NSString stringWithFormat:@"%@",@"http://47.104.139.178:8080/demo/paymentDetail/SavePackage"];
    //2.封装参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = [[NSUserDefaults standardUserDefaults] objectForKey:kPhoneNum];
    params[@"packages"] = packInfo.packagesStr;
    params[@"period"] = packInfo.periodStr;
    params[@"serviceCharge"] = packInfo.serviceChargeStr;
    params[@"idCard"] = packInfo.idCardStr;

    ResObject *result = [[ResObject alloc] init];
    
    [man postURL:urlInfo parameters:params success:^(id responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        
        if ([[responseObject objectForKey:@"Success"]  isEqual: @(YES)])
        {
            result.isSuccess = YES;
            callBack(result);
        }
        else
        {
            result.isSuccess = NO;
            result.errMsg = [responseObject objectForKey:@"errMsg"];
            callBack(result);
        }
    } failure:^(NSError *error, ParamtersJudgeCode judgeCode) {
        NSLog(@"judgeCode===>%lu",(unsigned long)judgeCode);
        
        result.isSuccess = NO;
        result.errMsg = @"请求失败!";
        callBack(result);
        
    }];
}


@end
